#ifndef _COSHIP_SDK_UTILITY_H
#define _COSHIP_SDK_UTILITY_H



#ifndef WINVER				
#define WINVER 0x0500		
#endif

#ifndef _WIN32_WINNT		
#define _WIN32_WINNT 0x0500	
#endif						

#ifndef _WIN32_WINDOWS		
#define _WIN32_WINDOWS 0x0410 
#endif

#ifndef _WIN32_IE			
#define _WIN32_IE 0x0600
#endif

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include "inttype.h"



namespace Util {

class CritSec
{
public:
	CritSec()
	{
		InitializeCriticalSection(&m_cs);
	}

	~CritSec()
	{
		DeleteCriticalSection(&m_cs);
	}

	void Lock()
	{
		EnterCriticalSection(&m_cs);
	}

	void Unlock()
	{
		LeaveCriticalSection(&m_cs);
	}

private:
	CRITICAL_SECTION m_cs;

	CritSec(const CritSec &);
	CritSec &operator=(const CritSec &);
};

class AutoLock
{
public:
	AutoLock(CritSec &cs)
		:m_cs(cs)
	{
		cs.Lock();
	}

	~AutoLock()
	{
		m_cs.Unlock();
	}

private:
	CritSec &m_cs;

	AutoLock();
	AutoLock(const AutoLock &);
	AutoLock &operator=(const AutoLock &);
};

template<class T>
static inline void DeleteObject(T *obj)
{
	delete obj;
}

}; //namespace Util

#endif
